﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Net;
using System.IO;

namespace GroundStation.Models
{
    // This is the parent class of all other message classes. When the Send Command (or abort or safe shutdown) button is pressed, any antenna or relay data that has changed will have a message sent to notify TowerTop that the antenna or relays need to change.
    // Standard Message format: X|X|XXXXXX
    //                          1|2|   3
    // Each X represents 1 byte of data (8 bytes total per message)
    // 1: Status byte (0 = Getter; 1 = Setter; 2 = TowerTop Response; 3 = Abort; 4 = Shutdown)
    // 2: Component Identifier (* = ALL known components; 1 = Azimuth; 2 = Altitude; 3 = Compass; 4 = Coupler Voltage; 5~9 = Relays 1~5)
    // 3: Data Payload
    // See the Communications Standards Section (in Design Level 2) in the design document for more information regarding these values
    public abstract class Message
    {
        private int _status;
        protected TcpClient messageSocket = SocketSingleton.messageClient;
        protected StreamWriter messageStream = SocketSingleton.messageStream;
        protected String commandString;
        public int PayLoad { get; set; }
        public int Status
        {
            get
            {
                return _status;
            } 
            set
            {
                _status = value;
            }
        }

        public void SendMessage()
        {
            commandString = commandString.PadRight(8, '0');
            char[] commandChars = commandString.ToCharArray();
            messageStream.WriteLine(commandChars);
            messageStream.Flush();
        }

        
        public abstract void SetPayload(String input);


        
    }
}
